package com.usian.admin.controller.v1;

import com.usian.admin.service.AdChannelService;
import com.usian.apis.admin.controller.AdChannelControllerApi;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.Path;

//频道管理的controller
@CrossOrigin
@RestController
@RequestMapping("/admin/api/v1/channel")
@Api(value = "频道管理",tags = "channel",description = "频道管理API")
public class AdChannelController implements AdChannelControllerApi {

    @Autowired
    private AdChannelService adChannelService;

    //根据name查询对象的channel数据
    @PostMapping("/list")
    @Override
    @ApiOperation(value = "查询频道信息",notes = "分页查询")
    @ApiImplicitParam(name = "channelDto" ,type = "channel",value = "分页参数")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto channelDto) {
        return adChannelService.findByNameAndPage(channelDto);
    }

    //添加
    @PostMapping("/save")
    @Override
    public ResponseResult save(@RequestBody AdChannel channel) {
        return adChannelService.saveChannel(channel);
    }

    //修改
    @PostMapping("/update")
    @Override
    public ResponseResult update(@RequestBody AdChannel channel) {
        return adChannelService.update(channel);
    }

    //删除
    @GetMapping("/del/{id}")
    @Override
    public ResponseResult deleteById(@PathVariable Integer id) {
        return adChannelService.deleteById(id);
    }
}
